package appapi.controller.oider;

import appapi.Global.BusinessException;
import appapi.common.BusinessTypeEnum;
import appapi.common.PassToken;
import appapi.common.ResponseBean;
import appapi.config.MyLog;
import appapi.model.ResponseDataModel;
import appapi.model.ResponseModel;
import appapi.service.ILoginService;
import appapi.utils.StringUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author djq
 * @date 2023/5/9 14:47
 * @description:
 */

@Api(tags = "登录")
@RestController
@RequestMapping(value = "/api/login")
public class LoginController {

    @Resource
    private ILoginService loginService;


    /**
     * 登录
     *
     * @return
     * @auther lc 2023/5/09
     */
    @ApiOperation(value = "用户登录", notes = "用户登录")
    @RequestMapping(value = "/Staff", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "account", dataType = "String", value = "账号"),
            @ApiImplicitParam(paramType = "query", name = "password", dataType = "String", value = "密码")
    })
    @MyLog(title = "登录",businessType = BusinessTypeEnum.other)
    @PassToken
    @CrossOrigin
    public ResponseBean StaffLogin(String account, String password) {
        try {
            //查询数据
            Map<String,Object> result = loginService.CheckLogin(account, password);
           return ResponseBean.success(result);
        }catch (BusinessException exception){
            return ResponseBean.fail("登录异常: ".concat(exception.getMessage()));
        }
    }


}
